﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using TTQT.TTQT_Code.Info;
public partial class XemKho : System.Web.UI.Page
{
    public bool isRole(string group_name)
    {
        try
        {
            return Session["group_names"].ToString().ToLower().IndexOf("," + group_name.ToLower() + ",") >= 0;
        }
        catch
        {
            return false;
        }
    }
    public UserInfo UserInfo
    {
        get
        {
            try
            {
                return (UserInfo)Session["UserInfo"];
            }
            catch
            {
                return new UserInfo();
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            bindTonKhoGrid();
            lblMaKho.Text = UserInfo.MaKho;
        }
        catch (Exception Exx)
        {
        }
    }
    protected void cmdRefresh_Click(object sender, EventArgs e)
    {
        bindTonKhoGrid();
    }
    private void gopKhoangTrang()
    {
        try
        {
            dsTonKho.UpdateCommandType = SqlDataSourceCommandType.StoredProcedure;
            dsTonKho.UpdateCommand = "KhoAnChi_GopKhoangAnChiTrang1Kho";
            dsTonKho.UpdateParameters.Clear();
            dsTonKho.UpdateParameters.Add(new Parameter("MaKho"));
            dsTonKho.UpdateParameters["MaKho"].DefaultValue = UserInfo.MaKho;
            dsTonKho.Update();
        }
        catch (Exception exxx)
        {
        }

    }
    private void bindTonKhoGrid()
    {
        try
        {
            //Goi ham gop khoang trang
            gopKhoangTrang();
            //Bind ton kho
            dsTonKho.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
            dsTonKho.SelectCommand = "KhoAnChi_GetByKhoHienTai";
            dsTonKho.SelectParameters.Clear();
            dsTonKho.SelectParameters.Add(new Parameter("KhoHienTai"));
            if (isRole("ttv"))
            {
                dsTonKho.SelectParameters["KhoHienTai"].DefaultValue = UserInfo.userName;
            }
            else
            {
                dsTonKho.SelectParameters["KhoHienTai"].DefaultValue = UserInfo.MaKho;
            }
            tonKhoGrid.DataSourceID = "dsTonKho";
            tonKhoGrid.DataBind();
        }
        catch (Exception Exxxx)
        {
        }

    }
    protected void tonKhoGrid_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
        try
        {
            if (e.Item.Cells[11].Text.Equals("Đang dùng"))
            {
                e.Item.CssClass = "DarkRow";
            }
            else
            {
                e.Item.CssClass = "LightRow";
            }
        }
        catch { }
    }
}
